package com.bigdata.service;

import com.bigdata.dao.UserDao;
import com.bigdata.dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {




        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //从请求中取出用户名和密码
        String username=request.getParameter("username");
        String password=request.getParameter("password");

        //2.去访问dao，是否满足登陆
        UserDao dao=new UserDaoImpl();
        boolean isSuccess=dao.login(username, password);

        //3.根据dao的返回结果，做出响应
        if(isSuccess){
            response.getWriter().write("登陆成功！");
            response.sendRedirect("index.html");
        }else{
            response.getWriter().write("登陆失败！");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        doGet(request, response);
    }


}
